package com.blb.dao.user.impl;

import com.blb.dao.user.UserDao;
import com.blb.pojo.User;
import com.blb.pojo.User;
import com.blb.utils.JDBCUtils;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.SQLException;

@Repository
public class UserDaoImpl implements UserDao {

    @Override
    public void register(User user) throws SQLException, ClassNotFoundException {
        Connection connection = JDBCUtils.getConnection();
        JDBCUtils.prepareStatement(connection,"insert into t_user(name,pass) values(?,?)",user.getName(),user.getPass()).executeUpdate();
        connection.close();
    }

    @Override
    public User selectByName(String name) throws Exception {
        Connection connection = JDBCUtils.getConnection();
        User user = JDBCUtils.getOne(connection, User.class, "select * from t_user where name = ?", name);
        connection.close();
        return user;
    }
}
